// pages/Census/selectIdentity/selectIdentity.js
const Controllers = require('../../controllers/Controller').controller;
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getIdentity()
  },



  //获取身份列表
  getIdentity(){
    Controllers.getIdentity().then(res=>{
      if(res.code==1){
        this.setData({
          list:res.data
        })
      }
      if(res.data.length<=0){
        wx.reLaunch({
          url: '/pages/Login/login',
        })
      }
    })
  },

  //选择身份
  selectIdentIty(e){
    let type=e.currentTarget.dataset.type
    let index=e.currentTarget.dataset.index
    wx.setStorageSync('agentLogin', this.data.list[index])
    app.globalData.agentIndexData=this.data.list[index]
    if(type==1){
      wx.setStorageSync("agentId",this.data.list[index].id)
      if(this.data.list[index].type==2){
        app.globalData.tabPage[2] = '/pages/Census/index'
        wx.setStorageSync('tabPage', app.globalData.tabPage);
        app.globalData.tabbar=[
          {
            "text": "首页",
            "iconPath": "/assets/images/fSecond/tab_icon_home_nor.png",
            "selectedIconPath": "/assets/images/fSecond/tab_icon_home_sel.png"
          },
          {
            "text": "商圈中心",
            "iconPath": "/assets/images/fSecond/tab_icon_sqzx_nor.png",
            "selectedIconPath": "/assets/images/fSecond/tab_icon_sqzx_sel.png"
          },
          {
            "text": "数据统计",
            "iconPath": "/assets/images/fSecond/tab_icon_sjtj_nor.png",
            "selectedIconPath": "/assets/images/fSecond/tab_icon_sjtj_sel.png"
          },
          {
            "text": "我的",
            "iconPath": "/assets/images/fSecond/tab_icon_me_nor.png",
            "selectedIconPath": "/assets/images/fSecond/tab_icon_me_sel.png"
          }
        ]
      }else{
        wx.setStorageSync('tabPage', app.globalData.tabPage3);
        app.globalData.tabbar=[
          {
            "text": "首页",
            "iconPath": "/assets/images/fSecond/tab_icon_home_nor.png",
            "selectedIconPath": "/assets/images/fSecond/tab_icon_home_sel.png"
          },
          {
            "text": "数据统计",
            "iconPath": "/assets/images/fSecond/tab_icon_sjtj_nor.png",
            "selectedIconPath": "/assets/images/fSecond/tab_icon_sjtj_sel.png"
          },
          {
            "text": "我的",
            "iconPath": "/assets/images/fSecond/tab_icon_me_nor.png",
            "selectedIconPath": "/assets/images/fSecond/tab_icon_me_sel.png"
          }
        ]
      }
    }else{
      wx.setStorageSync("agentId",this.data.list[index].agentId)
      wx.setStorageSync('tabPage', app.globalData.tabPage2);
      app.globalData.tabbar=[
        {
          "text": "首页",
          "iconPath": "/assets/images/fSecond/tab_icon_home_nor.png",
          "selectedIconPath": "/assets/images/fSecond/tab_icon_home_sel.png"
        },
        {
          "text": "数据统计",
          "iconPath": "/assets/images/fSecond/tab_icon_sjtj_nor.png",
          "selectedIconPath": "/assets/images/fSecond/tab_icon_sjtj_sel.png"
        },
        {
          "text": "我的",
          "iconPath": "/assets/images/fSecond/tab_icon_me_nor.png",
          "selectedIconPath": "/assets/images/fSecond/tab_icon_me_sel.png"
        }
      ]

      console.log(app.globalData.tabbar)
    }
    wx.redirectTo({
      url: '/pages/Index/Index'
    })
  }
})